import Vue from 'vue'
import VueRouter from 'vue-router'

Vue.use(VueRouter)

const routes = [{
    path: '/',
    redirect: '/login'
  },
  {
    path: '/login',
    name: 'login',
    component: () => import('@/views/login.vue')
  },
  {
    path: '/main',
    name: 'main',
    component: () => import('@/views/index/main.vue'),
    redirect: {
      name: 'index'
    },
    children: [{
        path: 'index',
        name: 'index',
        component: () => import('@/views/index/index/index.vue'),
        meta: {
          index: 0.1
        }
      },
      {
        path: 'indexAcountSetting',
        name: 'indexAcountSetting',
        component: () => import('@/views/index/index/indexAcountSetting.vue'),
      },
      {
        path: 'indexLoginLog',
        name: 'indexLoginLog',
        component: () => import('@/views/index/index/indexLoginLog.vue'),
      },
      {
        path: 'check',
        name: 'check',
        component: () => import('@/views/index/check/check.vue'),
      },

      {
        path: 'studentList',
        name: 'studentList',
        component: () => import('@/views/index/student/studentList.vue'),
      },
      {
        path: 'studentDetail',
        name: 'studentDetail',
        component: () => import('@/views/index/student/studentDetail.vue'),
      },
      {
        path: 'studentEdit',
        name: 'studentEdit',
        component: () => import('@/views/index/student/studentEdit.vue'),
      },
      {
        path: 'studentLog',
        name: 'studentLog',
        component: () => import('@/views/index/student/studentLog.vue'),
      },

      {
        path: 'schoolList',
        name: 'schoolList',
        component: () => import('@/views/index/school/schoolList.vue'),
      },
      {
        path: 'schoolAdd',
        name: 'schoolAdd',
        component: () => import('@/views/index/school/schoolAdd.vue'),
      },
      {
        path: 'schoolEdit',
        name: 'schoolEdit',
        component: () => import('@/views/index/school/schoolEdit.vue'),
      },


      {
        path: 'subjectList',
        name: 'subjectList',
        component: () => import('@/views/index/subject/subjectList.vue'),
      },
      {
        path: 'subjectAdd',
        name: 'subjectAdd',
        component: () => import('@/views/index/subject/subjectAdd.vue'),
      },
      {
        path: 'subjectEdit',
        name: 'subjectEdit',
        component: () => import('@/views/index/subject/subjectEdit.vue'),
      },


      {
        path: 'planList',
        name: 'planList',
        component: () => import('@/views/index/orderManage/plan/planList.vue'),
      },
      {
        path: 'planDetail',
        name: 'planDetail',
        component: () => import('@/views/index/orderManage/plan/planDetail.vue'),
      },


      {
        path: 'overseasList',
        name: 'overseasList',
        component: () => import('@/views/index/orderManage/overseas/overseasList.vue'),
      },
      {
        path: 'waitDeposit',
        name: 'waitDeposit',
        component: () => import('@/views/index/orderManage/overseas/waitDeposit.vue'),
      },
      {
        path: 'waitVerifyBaseInfo',
        name: 'waitVerifyBaseInfo',
        component: () => import('@/views/index/orderManage/overseas/waitVerifyBaseInfo.vue'),
      },
      {
        path: 'nopassBaseInfo',
        name: 'nopassBaseInfo',
        component: () => import('@/views/index/orderManage/overseas/nopassBaseInfo.vue'),
      },
      {
        path: 'waitChooseSchool',
        name: 'waitChooseSchool',
        component: () => import('@/views/index/orderManage/overseas/waitChooseSchool.vue'),
      },
      {
        path: 'waitStudentChoose',
        name: 'waitStudentChoose',
        component: () => import('@/views/index/orderManage/overseas/waitStudentChoose.vue'),
      },

      {
        path: 'waitText',
        name: 'waitText',
        component: () => import('@/views/index/orderManage/overseas/waitText.vue'),
      },
      {
        path: 'waitUploadInfo',
        name: 'waitUploadInfo',
        component: () => import('@/views/index/orderManage/overseas/waitUploadInfo.vue'),
      },
      {
        path: 'waitConfirmInfo',
        name: 'waitConfirmInfo',
        component: () => import('@/views/index/orderManage/overseas/waitConfirmInfo.vue'),
      },
      {
        path: 'waitPayFee',
        name: 'waitPayFee',
        component: () => import('@/views/index/orderManage/overseas/waitPayFee.vue'),
      },
      {
        path: 'waitCommitInfo',
        name: 'waitCommitInfo',
        component: () => import('@/views/index/orderManage/overseas/waitCommitInfo.vue'),
      },
      {
        path: 'waitVerify',
        name: 'waitVerify',
        component: () => import('@/views/index/orderManage/overseas/waitVerify.vue'),
      },
      {
        path: 'noPassVerify',
        name: 'noPassVerify',
        component: () => import('@/views/index/orderManage/overseas/noPassVerify.vue'),
      },
      {
        path: 'waitConfirmEnter',
        name: 'waitConfirmEnter',
        component: () => import('@/views/index/orderManage/overseas/waitConfirmEnter.vue'),
      },
      {
        path: 'waitWriteFee',
        name: 'waitWriteFee',
        component: () => import('@/views/index/orderManage/overseas/waitWriteFee.vue'),
      },
      {
        path: 'orderFinish',
        name: 'orderFinish',
        component: () => import('@/views/index/orderManage/overseas/orderFinish.vue'),
      },
      {
        path: 'applyProgress',
        name: 'applyProgress',
        component: () => import('@/views/index/orderManage/overseas/applyProgress.vue'),
      },
      {
        path: 'orderSetting',
        name: 'orderSetting',
        component: () => import('@/views/index/orderSetting/orderSetting.vue'),
      },
      {
        path: 'schoolSubject',
        name: 'schoolSubject',
        component: () => import('@/views/index/schoolSubject/schoolSubject.vue'),
      },
      {
        path: 'setting',
        name: 'setting',
        component: () => import('@/views/index/setting/setting.vue'),
      },

      {
        path: 'userManage',
        name: 'userManage',
        component: () => import('@/views/index/userManage/userManage.vue'),
      },
      {
        path: 'userAdd',
        name: 'userAdd',
        component: () => import('@/views/index/userManage/userAdd.vue'),
      },
      {
        path: 'userEdit',
        name: 'userEdit',
        component: () => import('@/views/index/userManage/userEdit.vue'),
      },
    ]

  }
]

//防止导航栏重复点击报错
const originalPush = VueRouter.prototype.push
VueRouter.prototype.push = function push(location) {
  return originalPush.call(this, location).catch(err => err)
}


const router = new VueRouter({
  mode: 'history',
  base: process.env.BASE_URL,
  routes
})

// 导航守卫
// 使用 router.beforeEach 注册一个全局前置守卫，判断用户是否登陆
router.beforeEach((to, from, next) => {
  if (to.path === '/login') {
    next();
  } else {
    let token = sessionStorage.getItem('Authorization');

    if (token === null || token === '') {
      next('/login');
    } else {
      next();
    }
  }
});

export default router